package es.us.idinfor.graph;

public class Vertex implements Comparable<Vertex> {
	private String id;
	private int pos;
	private long serial;
	
	public Vertex(String name, int n) {
		id = name;
		pos = n;
		serial = System.currentTimeMillis();
	}
	
	public String getId() {
		return id;
	}
	
	public int getPos() {
		return pos;
	}
	
	public int compareTo(Vertex o) {
		return (getPos() - o.getPos());
	}

	public int hashCode() {
		final int prime = 31;
		int result = 1;
		
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + (int) (serial ^ (serial >>> 32));
		
		return result;
	}

	public boolean equals(Object obj) {
		if(this == obj) {
			return true;
		}
		
		if(obj == null) {
			return false;
		}
		
		if(getClass() != obj.getClass()) {
			return false;
		}
		
		Vertex other = (Vertex) obj;
		
		if(id == null) {
			if(other.id != null) {
				return false;
			}
		}
		else if(!id.equals(other.id)) {
			return false;
		}
		
		if(serial != other.serial) {
			return false;
		}
		
		return true;
	}
	
	public String toString() {
		return id;
	}
}
